package com.telnetnz.ticketdesk.dao.wrapper;

import java.util.List;

import net.sf.ehcache.Cache;

import com.rockbb.common.dao.CacheManagerBean;
import com.telnetnz.ticketdesk.dao.entity.ProjectToUserEntity;
import com.telnetnz.ticketdesk.dao.mapper.ProjectToUserMapper;

public class ProjectToUserWrap {

	public static final String[] ORDER_BY = { 
		"project_name"
	};
	public static final String[] ORDER = {"DESC", "ASC"};
	public static final String[] ROLES = {"member", "manager"};

	private ProjectToUserMapper mapper;
	private Cache cache;

	public ProjectToUserWrap() {}

	public ProjectToUserWrap(
			ProjectToUserMapper mapper, 
			CacheManagerBean cacheManagerBean) {
		this.mapper = mapper;
		this.cache = cacheManagerBean.get(mapper.getClass().getName());
	}

	public ProjectToUserEntity selectByProjectIdAndUserId(int projectId, long userId) {
		ProjectToUserEntity entity = new ProjectToUserEntity();
		entity.setProjectId(projectId);
		entity.setUserId(userId);
		return mapper.selectByProjectIdAndUserId(entity);
	}

	public void insert(int projectId, long userId, int role)
	{
		ProjectToUserEntity entity = new ProjectToUserEntity();
		entity.setProjectId(projectId);
		entity.setUserId(userId);
		entity.setRole(role);
		mapper.insert(entity);
	}

	public void deleteProjectToUser(int projectId, long userId)
	{
		ProjectToUserEntity entity = new ProjectToUserEntity();
		entity.setProjectId(projectId);
		entity.setUserId(userId);
		mapper.delete(entity);
	}

	public void deleteByProjectId(int projectId)
	{
		mapper.deleteByProjectId(projectId);
	}

	public void deleteByUserId(long userId)
	{
		mapper.deleteByUserId(userId);
	}

	public List<ProjectToUserEntity> selectByUserId(long userId)
	{
		return mapper.selectByUserId(userId);
	}

	public List<ProjectToUserEntity> selectByProjectId(int projectId)
	{
		return mapper.selectByProjectId(projectId);
	}

	public Cache getCache() 
	{
		return cache;
	}
}

